package com.firewolf.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import utils.ConnectionUtils;

public class Sender {

	private static final String EXCHANGE_NAME = "publish_subscribe_exchange";

	public static void main(String[] args) throws Exception {

		Connection connection = ConnectionUtils.getMQConnection();

		Channel channel = connection.createChannel();

		// 声明交换机
		channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

		for (int i = 0; i < 20; i++) {
			String msg = "Hello,EveryOne"+i;
			// 把消息发送到交换机
			channel.basicPublish(EXCHANGE_NAME, "", null, msg.getBytes());
		}

		channel.close();
		connection.close();
	}
}
